﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SharpKml.Base;
using SharpKml.Dom;
using SharpKml.Dom.Atom;

namespace BlogAPIUnitTest
{
    /// <summary>
    /// Проверим, доступны ли сервисы и работают ли они как положено
    /// </summary>
    [TestClass]
    public class KMLTest
    {
        //[Test(Description = "Проверка создания объектов")]
        [TestMethod]
        public void ObjectsInit()
        {
            Kml test = Form();
        }

        public Kml Form()
        {
            Document Feature = new Document();
            Feature.AddStyle(new Style
            {
                Id = "stadionIcon",
                Icon = new IconStyle { Icon = new IconStyle.IconLink(new Uri("http://api-maps.yandex.ru/i/0.4/icons/stadium.png")) },
                Balloon = new BalloonStyle { BackgroundColor = new Color32(1, 255, 255, 187), Text = "<div style=\"font-size: 1.2em\">$[name]</div> <div>$[description]</div>" }
            });
            Feature.AddStyle(new Style
            {
                Id = "skatingIcon",
                Icon = new IconStyle { Icon = new IconStyle.IconLink(new Uri("http://api-maps.yandex.ru/i/0.4/icons/skating.png")) }
            });
            Folder fld = new Folder { Name = "Несколько спортивных сооружений" };
            fld.AddFeature(
                new Placemark
                {
                    StyleUrl = new Uri("#stadionIcon",UriKind.Relative),
                    Name = "Арена Химки",
                    Description = new Description { Text = "Московская обл., Химки, Кирова ул., 24" },
                    Geometry = new Point { Coordinate = new Vector(37.454121, 55.885055, 0) }
                });
            fld.AddFeature(
                new Placemark
                {
                    Name = "Метеор",
                    Description = new Description { Text = "Москва, Генерала Ермолова ул., 1" },
                    Geometry = new Point { Coordinate = new Vector(37.513422, 55.739934, 0) }
                });
            fld.AddFeature(
                new Placemark
                {
                    Name = "Вымпел",
                    Description = new Description { Text = "Москва, шоссе Измайловское, владение 73" },
                    Geometry = new Point { Coordinate = new Vector(37.754008, 55.790155, 0) }
                });
            fld.AddFeature(
                new Placemark
                {
                    Name = "Крылья Советов",
                    Description = new Description { Text = "Москва, Буденного просп., 17" },
                    Geometry = new Point { Coordinate = new Vector(37.724966, 55.774294) }
                });
            fld.AddFeature(
                new Placemark
                {
                    StyleUrl = new Uri("http://api-maps.yandex.ru/i/0.4/icons/swimming.png"),
                    Name = "Бассейн Медынский",
                    Description = new Description { Text = "Москва, Медынская ул., 9а, строение 2" },
                    Geometry = new Point { Coordinate = new Vector(37.651466, 55.581897) }
                });
            Feature.AddFeature(fld);

            Feature.AddFeature(new Placemark
            {
                Name = "extruded",
                Geometry = new LineString
                {
                    Extrude = true,
                    Tessellate = true,
                    AltitudeMode = AltitudeMode.RelativeToGround,
                    Coordinates = new CoordinateCollection() { new Vector(-122.364167, 37.824787, 50), new Vector(-122.363917, 37.824423, 50) }
                },
                Description = new Description { Text = "This is an image <img src=\"http://icon.jpg\" /> and we have a link http://www.google.com." }
            });

            var data = new Kml { Feature = Feature };
            Serializer serializer = new Serializer();
            serializer.SerializeRaw(data);

            Debug.WriteLine(serializer.Xml);
            return data;
        }
    }
}
